package com.shuzi.MediaShare.view;

import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.PauseOnScrollListener;

/**
 * 加载更多的监听器
 * @author lung
 *
 */
public class LoadMoreScrollListener extends PauseOnScrollListener
{
    private setOnScrollToEndListener listener;
   
    /**
     * @author lung
     *
     */
    public interface  setOnScrollToEndListener{
   
    void  loadMoreWhenScrollToEnd();
    }
   
    public LoadMoreScrollListener(ImageLoader imageLoader,
            boolean pauseOnScroll, boolean pauseOnFling,setOnScrollToEndListener setOnScrollToEndListener)
    {
        super(imageLoader, pauseOnScroll, pauseOnFling);
        this.listener = setOnScrollToEndListener;
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState)
    {
        super.onScrollStateChanged(view, scrollState);
        // 当不滚动时
        if (scrollState == OnScrollListener.SCROLL_STATE_IDLE)
        {
            // 判断滚动到底部
            if (view.getLastVisiblePosition() == (view.getCount() - 1))
            {
                listener.loadMoreWhenScrollToEnd();
            }
        }
    }

    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount)
    {
        // TODO Auto-generated method stub

    }
}